<?php

require_once 'TransactionCentral/UtilityFunctions.php';

abstract class TransactionCentral_Transaction extends TransactionCentral_CurlTransaction
{
    /*
     * TransactionCentral API URI's
     */
    const CC_TRANS_URL     = 'https://web.cert.transfirst.com/prigateway/creditcard.asmx/';
    const ACH_TRANS_URL    = 'https://web.cert.transfirst.com/checkverifyws/CheckVerifyws.asmx/';
    const RE_TRANS_URL     = 'https://web.cert.transfirst.com/prigateway/recurring.asmx/';
    
    /*
     * Yoru merchant ID and registry key.
     */
    const MERCH_ID    = '38216';
    const REG_KEY     = '8J4G9NADHQ7N43PB';
    
    /*
     * Card processing actions
     */
    const CC_SALE        = 'CreditCardSale';
	const CC_STATUS      = 'GetBankCardDebitStatus';
	const CC_VERIFY      = 'VerifyAccount';
	const CC_VOID        = 'VoidCreditCardSale';
	const CC_STATUSREF   = 'GetTransactionDetails';
	const CC_CREDIT      = 'CreditCardCredit';
    
	/*
	 * ACH processing actions
	 */
    const ACH_CREDIT    = 'ACHCredit';
    const ACH_DEBIT     = 'ACHDebit';
    const ACH_STATUS    = 'ACHTransactionStatus';
    const ACH_STATUSREF = 'GetTransactionDetails';
    const ACH_VERIFY    = 'ACHVerify';
    const ACH_VOID      = 'ACHVoidTransaction';
    
    public function __construct(Array $props = array())
	{
		$this->setAll($props);
	}
	
    public function setAll(Array $props)
    {
        foreach($props as $name => $value)
		{
    		$success = call_user_func(
            		                    array(
            		                              $this,
            		                              'set' . TransactionCentral_UtilityFunctions::toCamelCase($name, true)  
            		                          ),
            		                    $value
            		                 );
            		                 
            if(!$success) {
                throw new Exception("Illegal attempt to set nonexistant property " . $name . " in " . get_class($this) . '::' . __FUNCTION__ . '.');
            }
		}
    }
	
	/*
	 * Begin static functions.
	 */
	
	final public static function factory($type, Array $params = array())
	{
	    ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . realpath('..'));
	   
	    spl_autoload_register(array('TransactionCentral_UtilityFunctions', 'transactionCentralAutoLoader'));
	    
	    switch($type) {
	        case 'Card':
	            return new TransactionCentral_Card_Transaction($params);
	        break;
	        case 'ACH':
	            return new TransactionCentral_ACH_Transaction($params);
	        break;
	        case 'Recurring':
	            return new TransactionCentral_Recurring_Transaction($params);
	        break;
	        default:
	            
	        break;
	    }
	}
	
	abstract static function getStatus();
}